package com.util;

/**
 * @author liuchao
 * @version $Id: ZLibUtilsTest.java,v 0.1 2012-9-19 ����9:27:21 liuchao Exp $
 */
import static org.junit.Assert.*;  

import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileOutputStream;  
  
import org.junit.Test;  
  
/** 
 * ZLibѹ��������� 
 *  
 * @author <a href="mailto:zlex.dongliang@gmail.com">z��</a> 
 * @version 1.0 
 * @since 1.0 
 */  
public class ZLibUtilsTest {  
  
    @Test  
    public final void testBytes() {  
        System.err.println("�ֽ�ѹ���ѹ�����");  
        String inputStr = "����";  
        System.err.println("�����ַ�:\t" + inputStr);  
        byte[] input = inputStr.getBytes();  
        System.err.println("�����ֽڳ���:\t" + input.length);  
  
        byte[] data = ZLibUtils.compress(input);  
        System.err.println("ѹ����ֽڳ���:\t" + data.length);  
  
        System.err.println("ѹ�������:\t" + new String(data));  
        
        byte[] output = ZLibUtils.decompress(data);  
        System.err.println("��ѹ����ֽڳ���:\t" + output.length);  
        String outputStr = new String(output);  
        System.err.println("����ַ�:\t" + outputStr);  
  
        assertEquals(inputStr, outputStr);  
    }  
  
    @Test  
    public final void testFile() {  
        String filename = "zlib";  
        File file = new File(filename);  
        System.err.println("�ļ�ѹ���ѹ�����");  
        String inputStr = "snowolf@zlex.org;dongliang@zlex.org;zlex.dongliang@zlex.org";  
        System.err.println("�����ַ�:\t" + inputStr);  
        byte[] input = inputStr.getBytes();  
        System.err.println("�����ֽڳ���:\t" + input.length);  
  
        try {  
  
            FileOutputStream fos = new FileOutputStream(file);  
            ZLibUtils.compress(input, fos);  
            fos.close();  
            System.err.println("ѹ����ֽڳ���:\t" + file.length());  
        } catch (Exception e) {  
            fail(e.getMessage());  
        }  
  
        byte[] output = null;  
  
        try {  
            FileInputStream fis = new FileInputStream(file);  
            output = ZLibUtils.decompress(fis);  
            fis.close();  
  
        } catch (Exception e) {  
            fail(e.getMessage());  
        }  
        System.err.println("��ѹ����ֽڳ���:\t" + output.length);  
        String outputStr = new String(output);  
        System.err.println("����ַ�:\t" + outputStr);  
  
        assertEquals(inputStr, outputStr);  
    }  
} 